﻿Imports System.Data
Imports System.Reflection
Imports System.ComponentModel

Public Class UCMapeador
    Public Sub ReaderToObject(ByVal reader As IDataReader, ByVal oBE As Object)
        Dim Propiedades As PropertyInfo() = oBE.[GetType]().GetProperties()

        Dim N As Integer = 0
        For Each Propiedad As PropertyInfo In Propiedades
            Dim atributos As AttributeCollection = TypeDescriptor.GetProperties(oBE)(Propiedad.Name).Attributes
            N = reader.GetOrdinal(DirectCast(atributos(GetType(DescriptionAttribute)), DescriptionAttribute).Description)
            If Not (TypeOf reader.GetValue(N) Is System.DBNull) Then
                If Propiedad.PropertyType.Name = "DateTime" Then
                    Propiedad.SetValue(oBE, Convert.ToDateTime(reader.GetValue(N)), Nothing)
                Else
                    Propiedad.SetValue(oBE, reader.GetValue(N), Nothing)
                End If
                N += 1

            End If
        Next

    End Sub
End Class